package com.gome.axwl.aoc.web.controller.driver;

import com.cloudzone.cloudmq.api.open.base.SendResult;
import com.gome.axwl.aoc.common.util.DateUtil;
import com.gome.axwl.aoc.entity.mq.ImPushMsgMQEntityV31;
import com.gome.axwl.aoc.entity.po.MpResult;
import com.gome.axwl.aoc.web.controller.mq.producer.ImProducer;
import com.gome.commons.core.ErrorCode;
import com.gome.commons.core.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Description:
 * @Auther: yinyuxin@gome.com.cn
 * @Date: 2018/6/14 17:07
 */
@Api(tags = "mq测试")
@RestController
@RequestMapping(value = "/mq")
public class MqtestController {

    @Autowired
    private ImProducer imProducer;

    @Value("${gomeAxwlAocDriverIntegrationTag}")
    private String gomeAxwlAocDriverIntegrationTag;

    /**
     * 手动触发mq
     * @param date 时间 yyyy-MM 的字符串
     * @param ruleType 积分规则类别 0：好评率  1：准时送达率 2：接单天数
     * @author yinyuxin
     * @return
     */
    @ApiOperation(value = "手动触发mq",  notes = "development by yinyuxin")
    @ApiImplicitParam(name = "month", value = "时间", paramType = "query",dataType="String",required = false)
    @RequestMapping(value = "/sendMq",method = RequestMethod.GET)
    public ResultData sendMq(String month){
        if (StringUtils.isBlank(month))
            month=DateUtil.date2String(DateUtil.timeCalculation(new Date(),-1,1),DateUtil.FORMAT_DATE_WITHOUT_DAY);
        try {
            //司机积分的任务调度只用于定时调用积分生成的方法类，不包含任何业务逻辑

            ImPushMsgMQEntityV31 mqEntityV31=new ImPushMsgMQEntityV31();
            MpResult mpResult=new MpResult();
            mpResult.setMsgContent(month);
            mqEntityV31.setMpResult(mpResult);
            SendResult send = imProducer.send(gomeAxwlAocDriverIntegrationTag, mqEntityV31);
            return new ResultData(ErrorCode.SUCCESS,ErrorCode.SUCCESS_MSG);
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }

}
